﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x0200038B RID: 907
public class NetWWW : MonoBehaviour
{
	// Token: 0x17000231 RID: 561
	// (get) Token: 0x0600165D RID: 5725 RVA: 0x00095A50 File Offset: 0x00093C50
	// (set) Token: 0x0600165E RID: 5726 RVA: 0x00095A58 File Offset: 0x00093C58
	public bool NowConnecting { get; private set; }

	// Token: 0x0600165F RID: 5727 RVA: 0x00095A64 File Offset: 0x00093C64
	private void Awake()
	{
		this.connectingRoot.SetActive(this.NowConnecting);
	}

	// Token: 0x06001660 RID: 5728 RVA: 0x00095A78 File Offset: 0x00093C78
	public WWW Get(string url, string msg, NetWWW.ActWWW completeAct = null, NetWWW.ActWWW faildAct = null)
	{
		WWW www = new WWW(url);
		base.StartCoroutine(this.Wait(www, msg, completeAct, faildAct));
		return www;
	}

	// Token: 0x06001661 RID: 5729 RVA: 0x00095AA0 File Offset: 0x00093CA0
	public WWW Post(string url, string msg, WWWForm form, NetWWW.ActWWW completeAct = null, NetWWW.ActWWW faildAct = null)
	{
		WWW www = new WWW(url, form);
		base.StartCoroutine(this.Wait(www, msg, completeAct, faildAct));
		return www;
	}

	// Token: 0x06001662 RID: 5730 RVA: 0x00095ACC File Offset: 0x00093CCC
	public WWW Post(string url, string msg, Dictionary<string, string> post, NetWWW.ActWWW completeAct = null, NetWWW.ActWWW faildAct = null)
	{
		WWWForm wwwform = new WWWForm();
		foreach (KeyValuePair<string, string> keyValuePair in post)
		{
			wwwform.AddField(keyValuePair.Key, keyValuePair.Value);
		}
		return this.Post(url, msg, wwwform, completeAct, faildAct);
	}

	// Token: 0x06001663 RID: 5731 RVA: 0x00095B44 File Offset: 0x00093D44
	private IEnumerator Wait(WWW www, string msg, NetWWW.ActWWW completeAct = null, NetWWW.ActWWW faildAct = null)
	{
		Stopwatch sw = new Stopwatch();
		sw.Start();
		this.NowConnecting = true;
		this.connectingRoot.SetActive(this.NowConnecting);
		if (this.message != null)
		{
			this.message.text = msg;
		}
		bool isTimeOut = false;
		float timer = 0f;
		while (!www.isDone)
		{
			if (timer > this.timeOut)
			{
				isTimeOut = true;
				break;
			}
			timer += Time.deltaTime;
			yield return null;
		}
		bool success = !isTimeOut && string.IsNullOrEmpty(www.error);
		this.NowConnecting = false;
		this.connectingRoot.SetActive(this.NowConnecting);
		sw.Stop();
		float sec = (float)sw.ElapsedMilliseconds * 0.001f;
		GlobalData.Debug_Log("通信時間:" + sec);
		if (!success)
		{
			if (faildAct != null)
			{
				faildAct(www);
				www.Dispose();
			}
		}
		else if (completeAct != null)
		{
			completeAct(www);
		}
		yield break;
	}

	// Token: 0x04001A18 RID: 6680
	public float timeOut = 10f;

	// Token: 0x04001A19 RID: 6681
	[SerializeField]
	private GameObject connectingRoot;

	// Token: 0x04001A1A RID: 6682
	[SerializeField]
	private Text message;

	// Token: 0x0200038C RID: 908
	// (Invoke) Token: 0x06001665 RID: 5733
	public delegate void ActWWW(WWW www);
}
